// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.
{% include "utils/base.groovy.j2" with context %}
{% import 'utils/macros.j2' as m with context -%}

{% macro sharded_lint_step(name, num_shards, docker_image, node, ws) %}
{% for shard_index in range(1, num_shards + 1) %}
  '{{ name }} {{ shard_index }} of {{ num_shards }}': {
    node('{{ node }}') {
      ws({{ m.per_exec_ws(ws) }}) {
        init_git()
        docker_init({{ docker_image }})
        timeout(time: max_time, unit: 'MINUTES') {
          withEnv([
            'TVM_NUM_SHARDS={{ num_shards }}',
            'TEST_STEP_NAME={{ name }}',
            'TVM_SHARD_INDEX={{ shard_index - 1 }}',
            "SKIP_SLOW_TESTS=${skip_slow_tests}"], {
            {{ caller() | trim | indent(width=6) }}
          })
        }
      }
    }
  },
{% endfor %}
{% endmacro %}

stage('Lint') {
  parallel(
    {% call sharded_lint_step(
      name='Lint',
      num_shards=2,
      node='CPU-SMALL',
      ws='tvm/lint',
      docker_image='ci_lint',
    )
    %}
      sh (
        script: "${docker_run} ${ci_lint} ./tests/scripts/task_lint.sh",
        label: 'Run lint',
      )
    {% endcall %}
  )
}
